#include "MaterialUtils.h"

using namespace Ogre;

namespace utils
{
	MaterialPtr MaterialUtils::createColourMaterial(const String& name, const ColourValue&  colour)
	{
		MaterialPtr matptr =
		    MaterialManager::getSingleton().createOrRetrieve(name, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME).first;

		matptr->setReceiveShadows(true);
		Pass* pass = matptr->getTechnique(0)->getPass(0);
		pass->setDiffuse(colour);
		pass->setAmbient(colour);
		pass->setSpecular(colour);
		pass->setSelfIllumination(colour);
		//pass->setEmissive(ColourValue(0,0,0,colour.a));
		pass->setSceneBlending(SBT_TRANSPARENT_ALPHA);
		pass->setDepthWriteEnabled(false);

		return matptr;
	}

	Ogre::MaterialPtr MaterialUtils::createTextureMaterial(const Ogre::String& name, const Ogre::String& tex)
	{
		MaterialPtr matptr =
		    MaterialManager::getSingleton().createOrRetrieve(name, ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME).first;

		matptr->setReceiveShadows(true);
		Pass* pass = matptr->getTechnique(0)->getPass(0);
		TextureUnitState* tus = pass->createTextureUnitState(tex);

		return matptr;
	}
}
